package com.cyw.thread.threadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Author: Chenyw
 * @Date: 2022/09/21/10:04
 */

class NewThread5 implements Runnable{
    @Override
    public void run()
    {
        for(int i=0;i<100;i++)
        {
            if(i%2==0)
            {
                System.out.println(Thread.currentThread().getName()+"偶数："+i);
            }
        }
    }
}
class NewThread6 implements Runnable{
    @Override
    public void run()
    {
        for(int i=0;i<100;i++)
        {
            //判断是奇数
            if(i%2!=0)
            {
                System.out.println(Thread.currentThread().getName()+"奇数："+i);
            }
        }
    }
}

public class ThreadPool {
    public static void main(String[] args) {
//service是线程池
        ExecutorService service = Executors.newFixedThreadPool(10);
        NewThread5 newThread5 = new NewThread5();
        NewThread6 newThread6 = new NewThread6();
        //输出偶数的线程
        //适合于Runnable
        service.execute(newThread5);
        //输出奇数的线程
        service.execute(newThread6);
        //适合Callable
        //  service.submit()
        //关闭线程池
        service.shutdown();
    }
}
